package com.archstoday.activity;

import android.app.Dialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.archstoday.BaseApp;
import com.archstoday.R;
import com.archstoday.common.SpfUtils;
import com.archstoday.entity.BaseEntity;
import com.archstoday.service.NetBroadcastReceiver;
import com.archstoday.utils.ToolUtils;
import com.base.activity.BaseActivity;
import com.base.http.common.BaseHttpClient;
import com.base.utils.MySharedPreferencesMgr;

/**
 * 基础页面类-不支持滑动
 */
public class AsBaseActivity extends BaseActivity {

    public BaseApp mApp;

    @Override
    protected void initView(Bundle bundle) {
        mApp = (BaseApp) getApplication();
    }

    @Override
    protected void initData(Bundle bundle) {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void onSuccess(String content, BaseHttpClient client, Object parse) {

    }

    @Override
    protected void onError(Throwable error, BaseHttpClient client) {
        new Thread() {
            @Override
            public void run() {
                new Handler(Looper.getMainLooper()).post(runnable);
            }
        }.start();
    }

    @Override
    protected void intentState(boolean state) {

    }

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            showToast(R.string.intent_error);
        }
    };

    public void getEvent(String e, String pageType) {
        initParameter();
        mParams.put("e", e);
        mParams.put("accountId", MySharedPreferencesMgr.getString(SpfUtils.USER_ID, null));
        mParams.put("deviceId", mApp.getDeviceID(mContext));
        mParams.put("platform", "android");
        mParams.put("appId", "200000");
        mParams.put("pageType", pageType);

        sendGetRequest(mApp.EVENT_URL, "event", mParams, BaseEntity.class);
    }

    public void getEvent(String e, String pageType, String info) {
        initParameter();
        mParams.put("e", e);
        mParams.put("accountId", MySharedPreferencesMgr.getString(SpfUtils.USER_ID, null));
        mParams.put("deviceId", mApp.getDeviceID(mContext));
        mParams.put("platform", "android");
        mParams.put("appId", "200000");
        mParams.put("pageType", pageType);
        mParams.put("info", info);

        sendGetRequest(mApp.EVENT_URL, "event", mParams, BaseEntity.class);
    }

    /**
     * 底部分享栏
     */
    private Dialog mShareDialog;
    public void setDialog() {
        mShareDialog = new Dialog(this, R.style.BottomDialog);
        View view = LayoutInflater.from(this).inflate(
                R.layout.layout_share, null);
        //初始化视图
        view.findViewById(R.id.share_wx_btn).setOnClickListener(click);
        view.findViewById(R.id.share_group_btn).setOnClickListener(click);
        view.findViewById(R.id.share_link_btn).setOnClickListener(click);
        view.findViewById(R.id.share_cancel_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismissShare();
            }
        });
        mShareDialog.setContentView(view);
        Window dialogWindow = mShareDialog.getWindow();
        dialogWindow.setGravity(Gravity.BOTTOM);
        WindowManager.LayoutParams lp = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        lp.x = 0; // 新位置X坐标
        lp.y = 0; // 新位置Y坐标
        lp.width = (int) getResources().getDisplayMetrics().widthPixels; // 宽度
        view.measure(0, 0);
        lp.height = view.getMeasuredHeight();

        lp.alpha = 9f; // 透明度
        dialogWindow.setAttributes(lp);
        mShareDialog.show();
    }

    public void dismissShare() {
        if (mShareDialog != null) {
            mShareDialog.dismiss();
        }
    }
}